<?php

namespace App\Http\Controllers\Signature;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Kaxiluo\ApiSignature\Client\GuzzleClientFactory;

class IndexController extends Controller
{
    public function __construct()
    {
        $this->middleware('signature-verify')->only('server');
    }

    public function client(Request $request)
    {
        $config = [
            'base_uri' => 'https://172.16.13.76',
            'verify' => false,
        ];
        $client = GuzzleClientFactory::createClient('1', 'iamsecret', $config);

        $res = $client->request(
            'POST',
            '/signature/server?a=b&q= bmw&9',
            [
                'headers' => ['X-a' => 'aaa'],
                'body' => json_encode(['jj' => 'ss'])
            ]
        );

        var_dump('laravel client received:' . $res->getHeaderLine('Content-Type'));
        var_dump('laravel client received:' . $res->getBody()->getContents());

        return response()->json(['laravel signature client end']);
    }

    public function server(Request $request)
    {
        Log::info('header ' . var_export($request->header(), true));
        Log::info('getQueryString ' . $request->getQueryString());
        Log::info('getContent ' . $request->getContent());
        return response()->json(['laravel signature server end']);
    }
}
